﻿using EnetaMvc.Core.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnetaMvc.Core.Domain.Content;
using NHibernate;
using EnetaMvc.Infrastructure;
using System.Diagnostics;

namespace EnetaMvc.Data.NHibernate.Repositories
{
    public class HtmlControlRepository : BaseRepository, IHtmlControlRepository
    {
        private readonly ISession _session;

        public HtmlControlRepository(IMapperSession session)
            : base(((NHSession)session).GetCurrentSession())
        {
            _session = ((NHSession)session).GetCurrentSession();
            Debug.WriteLine("NH hash: " + _session.GetHashCode());
        }

        public IList<HtmlControl> ListHtmlControls()
        {
            return _session.CreateCriteria<HtmlControl>().List<HtmlControl>();
        }

        public HtmlControl GetHtmlControlById(long id)
        {
            return _session.Get<HtmlControl>(id);
        }

        public void SaveHtmlControl(HtmlControl htmlControl)
        {
            SaveInTransaction(htmlControl);
        }

        public void DeleteHtmlControl(long id)
        {
            DeleteInTransaction(GetHtmlControlById(id));
        }
    }
}
